package com.loong.testretrofitrxjavamvp.presenter;

import android.util.Log;

import com.loong.testretrofitrxjavamvp.api.Api;
import com.loong.testretrofitrxjavamvp.bean.TranslationBean;
import com.loong.testretrofitrxjavamvp.inf.pres.IMainPres;
import com.loong.testretrofitrxjavamvp.inf.view.IMainView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


/**
*  @describe  -- presenter层，主要做数据逻辑处理
*  @author zgq
*  @version 1.0.0
*  @date 2018/11/13
*/
public class MainPresenter extends BasePresenter<IMainView> implements IMainPres{

    @Override
    public void netData(String content) {
        Api.getInstance().getService().translation(content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<TranslationBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addReqs(d);
                        Log.e("fl", "onSubscribe");
                    }

                    @Override
                    public void onNext(TranslationBean translationBean) {
                        mView.getDisplayData(translationBean.getContent().getOut());
                        Log.e("fl", "onNext");
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showError(0, e);
                        Log.e("fl", "onError");
                    }

                    @Override
                    public void onComplete() {
                        mView.complete(0);
                        Log.e("fl", "onComplete");
                    }
                });

    }


}
